<?php
class Mlink extends CI_Model {
	function __construct() {
		parent::__construct ();
	}
	
	function getLinkNum() {
		return $this->db->count_all ( 'link' );
	}
	
	function getLinkList($page, $num) {
		$this->db->order_by ( "updateTime", "desc" );
		$this->db->limit ( $num, $page );
		$query = $this->db->get ( 'link' );
		return $query->result_array ();
	}
	
	function addLink($data) {
		$this->db->insert ( 'link', $data );
		return $this->db->insert_id ();
	}
	
	function updateLink($data, $id) {
		$this->db->where ( 'id', $id );
		$this->db->update ( 'link', $data );
		if ($this->db->affected_rows () > 0)
			return TRUE;
		else
			return FALSE;
	}
	
	function delLinkbyId($id) {
		$this->db->where ( 'id', $id );
		$this->db->delete ( 'link' );
		if ($this->db->affected_rows () > 0)
			return TRUE;
		else
			return FALSE;
	}
	
	function getLinkbyId($id) {
		$this->db->where ( 'id', $id );
		$query = $this->db->get ( 'link' );
		return $query->row_array ();
	}
}